#DCONFIG_MSPROTOCOL_LIBRTMP 

D_BASEAPI_FLAGS= \
    -DOS_LINUX_SOC \
    -D__STDC_FORMAT_MACROS \
    -DCONFIG_MSPROTOCOL_MSAV \
    -DCONFIG_MSPROTOCOL_TSSL

D_BASEAPI_FLAGS_SIMPLE= \
    -DOS_LINUX_SOC \
    -D__STDC_FORMAT_MACROS

D_LIBMSLOG_LIBS	:=`pkg-config --libs	libmslog`
D_LIBMSLOG_INCLUDES	:=`pkg-config --cflags	libmslog`
D_LIBMSCOMMON_LIBS	:=`pkg-config --libs	libmscommon`
D_LIBMSCOMMON_INCLUDES	:=`pkg-config --cflags	libmscommon`
D_LIBPROTOCOL_LIBS	:=`pkg-config --libs	libmsprotocol`
D_LIBPROTOCOL_INCLUDES	:=`pkg-config --cflags	libmsprotocol`
#librtmp
D_LIBRTMP_LIBS		:=`pkg-config --libs	librtmp`
D_LIBRTMP_INCLUDES	:=`pkg-config --cflags	librtmp`
#openssl
D_OPENSSL_LIBS		:=`pkg-config --libs	openssl`
D_OPENSSL_INCLUDES	:=`pkg-config --cflags	openssl`
#ffmpeg
D_FFMPEG_LIBS=\
	`pkg-config --libs libavcodec` \
	`pkg-config --libs libavfilter` \
	`pkg-config --libs libavformat` \
	`pkg-config --libs libavutil` \
	`pkg-config --libs libavdevice` \
	`pkg-config --libs libswresample` \
	`pkg-config --libs libpostproc` \
	`pkg-config --libs libswscale`
D_FFMPEG_INCLUDES= \
	`pkg-config --cflags libavcodec` \
	`pkg-config --cflags libavfilter` \
	`pkg-config --cflags libavformat` \
	`pkg-config --cflags libavutil` \
	`pkg-config --cflags libavdevice` \
	`pkg-config --cflags libswresample` \
	`pkg-config --cflags libpostproc` \
	`pkg-config --cflags libswscale`

C_INCLUDE:=${D_LIBMSLOG_INCLUDES} ${D_LIBMSCOMMON_INCLUDES} ${D_FFMPEG_INCLUDES} ${D_OPENSSL_INCLUDES}  ${D_BASEAPI_FLAGS} -Isrc 
C_LIBS	 :=${D_LIBMSLOG_LIBS}     ${D_LIBMSCOMMON_LIBS}     ${D_FFMPEG_LIBS}     ${D_OPENSSL_LIBS}      -pthread -lm 
C_SIMPLE_INCLUDE:=${D_LIBMSLOG_INCLUDES} ${D_LIBMSCOMMON_INCLUDES}   ${D_BASEAPI_FLAGS_SIMPLE} -Isrc 
C_SIMPLE_LIBS	:=${D_LIBMSLOG_LIBS}     ${D_LIBMSCOMMON_LIBS}        -pthread -lm 

libmsprotocol_CC=${CC}
libmsprotocol_SRC=${C_SRC}
libmsprotocol_CFLAGS=${C_INCLUDE} ${C_LIBS} ${CFLAGS_SHARE} -fPIC 

libmsprotocol_simple_CC=${CC}
libmsprotocol_simple_SRC=${C_SRC}
libmsprotocol_simple_CFLAGS=${C_SIMPLE_INCLUDE} ${C_SIMPLE_LIBS} ${CFLAGS_SHARE} -fPIC


msprotocol_api_sample_CC=${CC}
msprotocol_api_sample_SRC=${C_SRC} msprotocol_api_sample.c
msprotocol_api_sample_CFLAGS= ${D_LIBPROTOCOL_LIBS} ${D_LIBPROTOCOL_INCLUDES} ${C_INCLUDE} ${C_LIBS}

msprotocol_api_test_CC=${CC}
msprotocol_api_test_SRC=${C_SRC} msprotocol_api_test.c
msprotocol_api_test_CFLAGS=   ${D_LIBPROTOCOL_LIBS} ${D_LIBPROTOCOL_INCLUDES} ${C_INCLUDE} ${C_LIBS}

msprotocol_api_sample_srtserver_CC=${CC}
msprotocol_api_sample_srtserver_SRC=${C_SRC} msprotocol_api_sample_srtserver.c
msprotocol_api_sample_srtserver_CFLAGS= ${D_LIBPROTOCOL_LIBS} ${D_LIBPROTOCOL_INCLUDES} ${C_INCLUDE} ${C_LIBS}

msprotocol_api_sample_srtclient_CC=${CC}
msprotocol_api_sample_srtclient_SRC=${C_SRC} msprotocol_api_sample_srtclient.c
msprotocol_api_sample_srtclient_CFLAGS= ${D_LIBPROTOCOL_LIBS} ${D_LIBPROTOCOL_INCLUDES} ${C_INCLUDE} ${C_LIBS}



x8664: libmsprotocol install msprotocol_api_sample msprotocol_api_test

simple: libmsprotocol_simple install
	
libmsprotocol: 
	mkdir -p $(OUT_LIB)
	mkdir -p $(OUT_INCLUDE)
	cp -fr src/*.h $(OUT_INCLUDE)
	$($@_CC)  $($@_SRC)  $($@_CFLAGS)  -o $(OUT_LIB)/$(PROGRAM_NAME).so 
libmsprotocol_simple: 
	mkdir -p $(OUT_LIB)
	mkdir -p $(OUT_INCLUDE)
	cp -fr src/*.h $(OUT_INCLUDE)
	$($@_CC)  $($@_SRC)  $($@_CFLAGS)  -o $(OUT_LIB)/libmsprotocol.so 
gdbs: 
	mkdir -p $(OUT_LIB)
	mkdir -p $(OUT_INCLUDE)
	cp -fr src/*.h $(OUT_INCLUDE)
	$(libmsprotocol_CC)  $(libmsprotocol_SRC)  $(libmsprotocol_CFLAGS) -g -o $(OUT_LIB)/$(PROGRAM_NAME).so  	
	
sample: msprotocol_api_sample  msprotocol_api_test

msprotocol_api_sample: 
	mkdir -p $(OUT_BIN)
	$($@_CC)  $($@_SRC)  $($@_CFLAGS)  -o $(OUT_BIN)/$@ 
	cp $(OUT_BIN)/$@ ${prefix_x8664}/bin/mscore_mctu -fr
msprotocol_api_test: 
	mkdir -p $(OUT_BIN)
	$($@_CC)  $($@_SRC)  $($@_CFLAGS) -g -o out/bin/$@ 
	cp $(OUT_BIN)/$@ ${prefix_x8664}/bin/mscore_test_concurrent -fr

msprotocol_api_sample_srtserver: 
	mkdir -p $(OUT_BIN)
	$($@_CC)  $($@_SRC)  $($@_CFLAGS)  -o out/bin/$@ 
msprotocol_api_sample_srtclient: 
	mkdir -p $(OUT_BIN)
	$($@_CC)  $($@_SRC)  $($@_CFLAGS)  -o out/bin/$@ 
install:
	mkdir -p  ${prefix_x8664}/lib/ 
	mkdir -p  ${prefix_x8664}/include/   
	mkdir -p  ${prefix_x8664}/lib/pkgconfig/ 
	cp -fr $(OUT_LIB)/$(PROGRAM_NAME).so	${prefix_x8664}/lib/     
	cp -fr $(OUT_INCLUDE)			${prefix_x8664}/include/	     
	cp -fr platform/$(PROGRAM_NAME).pc	${prefix_x8664}/lib/pkgconfig/
	ldconfig
install_gdb:
	mkdir -p  ${prefix_x8664}/lib_gdb/ 
	mkdir -p  ${prefix_x8664}/include/   
	mkdir -p  ${prefix_x8664}/lib/pkgconfig/ 
	cp -fr $(OUT_LIB)/$(PROGRAM_NAME).so	${prefix_x8664}/lib_gdb/     
	cp -fr $(OUT_INCLUDE)			${prefix_x8664}/include/	     
	cp -fr platform/$(PROGRAM_NAME).pc	${prefix_x8664}/lib/pkgconfig/
uninstall:
	rm -fr ${prefix_x8664}/lib/$(PROGRAM_NAME).so 
	rm -fr ${prefix_x8664}/include/$(PROGRAM_NAME)
	rm -fr ${prefix_x8664}/lib/pkgconfig/$(PROGRAM_NAME).pc
	rm -fr ${prefix_x8664}/bin/mscore_mctu
	rm -fr ${prefix_x8664}/bin/mscore_test_concurrent
